<?php
namespace Base;
use Exception;
use Jwt\Token;
use JetBrains\PhpStorm\NoReturn;

/**
 * Api用户总控制器
 */
class UserController extends BaseController
{
    /**
     * 含用户数据
     * @var array
     */
    protected array $token = [];

    /**
     * @var string 域名
     */
    protected string $host = "";

    /**
     * @var int 用户id
     */
    protected int $member_id;

    /**
     * 初始化
     */
    #[NoReturn] public function init(): void
    {
        $this->host = getRequestHost();
        try {
            //验证 token
            $resultToken = Token::verify();
            if($resultToken === false) {
                $this->apiError(Token::get_msg(), Token::get_status());
            }else{
                $this->token = $resultToken;
            }
            $this->member_id = $resultToken['member_id'];
            //接口签名验证
            $this->verifySign();
        } catch (Exception $e) {
            $this->apiError($e->getMessage());
        }
    }
}
